home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 19.2 KB | 685 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // USectionMgr.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __USECTIONMGR__
- #include "USectionMgr.h"
- #endif
-
- // MacApp
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UBUSYCURSOR__
- #include "UBusyCursor.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDESKSCRAPVIEW__
- #include "UDeskScrapView.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UEDITIONDOCUMENT__
- #include "UEditionDocument.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include "UFileBasedDocument.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USECTION__
- #include "USection.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // private global variables
- Boolean pSectionMgrInitialized;
-
-
- //========================================================================================
- // CLASS TSectionMgr
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment MAInit
- MA_DEFINE_CLASS_M1(TSectionMgr, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionMgr::TSectionMgr:
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionMgr::TSectionMgr()
- {
- fSectionList = NULL;
- } // TSectionMgr::TSectionMgr
-
- //----------------------------------------------------------------------------------------
- // TSectionMgr::ISectionMgr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TSectionMgr::ISectionMgr()
-
- {
- this->IBehavior(kSectionMgrBehaviorID);
-
- FailInfo fi;
- Try(fi)
- {
- TSectionList* aSectionList = new TSectionList;
- aSectionList->ISectionList();
- fSectionList = aSectionList;
- #if qDebug
- fSectionList->SetEltType("TSection"); // takes MAName
- #endif
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- } // TSectionMgr::ISectionMgr
-
- //----------------------------------------------------------------------------------------
- // TSectionMgr::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TSectionMgr::~TSectionMgr()
-
- {
- fSectionList = (TSectionList *) FreeIfObject(fSectionList);
- // the preceding should be FreeListIfObject ... NOT!
- } // TSectionMgr::Free
-
- //----------------------------------------------------------------------------------------
- // TSectionMgr::DoAESectionEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TSectionMgr::DoAESectionEvent(CommandNumber aCommandNumber,
- const AppleEvent& message,
- const AppleEvent& reply)
- {
- TSectionCommand* theCommand = NULL;
-
- switch (aCommandNumber)
- {
- case cSectionRead:
- theCommand = new TSectionReadEventCommand;
- break;
-
- case cSectionWrite:
- theCommand = new TSectionWriteEventCommand;
- break;
-
- case cSectionScroll:
- theCommand = new TSectionScrollEventCommand;
- break;
-
- case cSectionCancel:
- theCommand = new TSectionCancelEventCommand;
- break;
- }
-
- if (theCommand)
- {
- theCommand->ISectionCommand(aCommandNumber, message, reply);
- fOwner->PostCommand(theCommand);
- }
- } // TSectionMgr::DoAESectionEvent
-
-
- //========================================================================================
- // CLASS TSectionCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment MASectionNonRes
- MA_DEFINE_CLASS_M1(TSectionCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionCommand::TSectionCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionCommand::TSectionCommand()
- {
- fSection = NULL;
- } // TSectionCommand::TSectionCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionCommand::~TSectionCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionCommand::ISectionCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASectionNonRes
-
- void TSectionCommand::ISectionCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TSection* itsSection)
-
- {
- this->IServerCommand(itsCommandNumber, itsDocument, kCantUndo, kDoesNotCauseChange, itsDocument);
-
- fSection = itsSection;
- } // TSectionCommand::ISectionCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionCommand::ISectionCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TSectionCommand::ISectionCommand(CommandNumber itsCommandNumber,
- const AppleEvent& itsMessage,
- const AppleEvent& itsReply)
-
- {
- IServerCommand(itsCommandNumber, gDispatcher, kCantUndo, kDoesNotCauseChange, NULL,
- itsMessage, itsReply);
-
- FailInfo fi;
-
- Try(fi)
- {
- // get the section handle
- SectionHandle aSectionHandle = fMessage->ReadSectionHandle(keyDirectObject);
- #if qDebug
- if (gIntenseDebugging)
- fprintf(stderr, "SectionHandle from AppleEvent = %ld \n", (long)aSectionHandle);
- #endif
-
- // find the section object
- fSection = NULL;
- { // for correct failure handling
- TSectionMgr* aSectionMgr =
- (TSectionMgr*) gDispatcher->GetBehaviorWithIdentifier(kSectionMgrBehaviorID);
- CSectionIterator iter(aSectionMgr->fSectionList);
- TSection* aSection;
- for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- {
- if (aSection->fSectionHandle == aSectionHandle)
- {
- fSection = aSection;
- break;
- }
- }
- }
- if (!fSection)
- Failure(noErr, 0); // silent failure
-
- // associate the command correctly
- fContext = fSection->fDocument;
- #if qDebug
- if (!IsObject(fContext))
- {
- VerboseIsObject(fContext);
- ProgramBreak("the section object's document appears to be corrupt");
- }
- #endif
-
- // ensure that the section is registered
- FailOSErr(fSection->Register());
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TSectionCommand::ISectionCommand
-
-
- //========================================================================================
- // CLASS TSectionReadEventCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionCommand
-
- #pragma segment MASectionNonRes
- MA_DEFINE_CLASS_M1(TSectionReadEventCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionReadEventCommand::TSectionReadEventCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionReadEventCommand::TSectionReadEventCommand()
- {
- } // TSectionReadEventCommand::TSectionReadEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionReadEventCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionReadEventCommand::~TSectionReadEventCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionReadEventCommand::ISectionReadEventCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASectionNonRes
-
- void TSectionReadEventCommand::ISectionReadEventCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TSubscriber* itsSubscriber)
-
- {
- this->ISectionCommand(itsCommandNumber, itsDocument, itsSubscriber);
-
- fCausesChange = kCausesChange;
- } // TSectionReadEventCommand::ISectionReadEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionReadEventCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionReadEventCommand::DoIt() // override
- {
- // FailInfo fi;
- // Try(fi)
- // {
- TSubscriber * aSubscriber = (TSubscriber *)fSection;
-
- if ((!aSubscriber->fDocument->fStopAllEditions) && (aSubscriber->GetUpdateMode() == sumAutomatic))
- aSubscriber->Subscribe();
-
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error);
- //
- // fi.ReSignal();
- // }
- } // TSectionReadEventCommand::DoIt
-
-
- //========================================================================================
- // CLASS TSectionWriteEventCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionCommand
-
- #pragma segment MASectionNonRes
- MA_DEFINE_CLASS_M1(TSectionWriteEventCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionWriteEventCommand::TSectionWriteEventCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionWriteEventCommand::TSectionWriteEventCommand()
- {
- } // TSectionWriteEventCommand::TSectionWriteEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionWriteEventCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionWriteEventCommand::~TSectionWriteEventCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionWriteEventCommand::ISectionWriteEventCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASectionNonRes
-
- void TSectionWriteEventCommand::ISectionWriteEventCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TPublisher* itsPublisher)
-
- {
- this->ISectionCommand(itsCommandNumber, itsDocument, itsPublisher);
- } // TSectionWriteEventCommand::ISectionWriteEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionWriteEventCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionWriteEventCommand::DoIt() // override
- {
- // FailInfo fi;
- // Try(fi)
- // {
- TFile* itsFile = NULL;
- TFileBasedDocument* aFileBasedDocument = fSection->fDocument;
- if (aFileBasedDocument && aFileBasedDocument->FileExists())
- itsFile = aFileBasedDocument->GetFile();
-
- ((TPublisher *)fSection)->Publish(itsFile);
-
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error);
- //
- // fi.ReSignal();
- // }
-
- } // TSectionWriteEventCommand::DoIt
-
-
- //========================================================================================
- // CLASS TSectionScrollEventCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionCommand
-
- #pragma segment MASectionNonRes
- MA_DEFINE_CLASS_M1(TSectionScrollEventCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionScrollEventCommand::TSectionScrollEventCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionScrollEventCommand::TSectionScrollEventCommand()
- {
- } // TSectionScrollEventCommand::TSectionScrollEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionScrollEventCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionScrollEventCommand::~TSectionScrollEventCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionScrollEventCommand::ISectionScrollEventCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASectionNonRes
-
- void TSectionScrollEventCommand::ISectionScrollEventCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TSection* itsSection)
-
- {
- this->ISectionCommand(itsCommandNumber, itsDocument, itsSection);
- } // TSectionScrollEventCommand::ISectionScrollEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionScrollEventCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionScrollEventCommand::DoIt() // override
- {
- // at this point, the application has received and processed the 'odoc' AppleEvent
- // so, the window containing the section should be frontmost
-
- // FailInfo fi;
- // Try(fi)
- // {
- // 1. bring the application to front (using the Process Manager)
- gDispatcher->MakeFrontProcess();
-
- // 2. tell the document to reveal the selection and select it
- if (fContext)
- ((TEditionDocument*)fContext)->RevealSelection(fSection->fDesignator);
-
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error);
- //
- // fi.ReSignal();
- // }
- } // TSectionScrollEventCommand::DoIt
-
-
- //========================================================================================
- // CLASS TSectionCancelEventCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionCommand
-
- #pragma segment MASectionNonRes
- MA_DEFINE_CLASS_M1(TSectionCancelEventCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand::TSectionCancelEventCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionCancelEventCommand::TSectionCancelEventCommand()
- {
- } // TSectionCancelEventCommand::TSectionCancelEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionCancelEventCommand::~TSectionCancelEventCommand()
- {
- if (fCommandDone && (fSection != NULL))
- {
- fSection->Delete();
- fSection = (TSection*) FreeIfObject(fSection);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand::ISectionCancelEventCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASectionNonRes
-
- void TSectionCancelEventCommand::ISectionCancelEventCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TSection* itsSection)
-
- {
- this->ISectionCommand(itsCommandNumber, itsDocument, itsSection);
-
- fCanUndo = kCanUndo; // can undo the cancel
- fCausesChange = kCausesChange;
- } // TSectionCancelEventCommand::ISectionCancelEventCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionCancelEventCommand::DoIt() // override
- {
- // FailInfo fi;
- // Try(fi)
- // {
- fSection->CancelSection(kCancel);
- ((TEditionDocument*)fContext)->DoDeleteBorder(fSection);
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error);
- // fi.ReSignal();
- // }
- } // TSectionCancelEventCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionCancelEventCommand::UndoIt() // override
- {
- // FailInfo fi;
- // Try(fi)
- // {
- fSection->CancelSection(!kCancel);
- ((TEditionDocument *)fContext)->DoAddBorder(fSection);
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error);
- // fi.ReSignal();
- // }
- } // TSectionCancelEventCommand::UndoIt
-
- //----------------------------------------------------------------------------------------
- // TSectionCancelEventCommand::Commit:
- //----------------------------------------------------------------------------------------
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUSectionMgr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void InitUSectionMgr()
-
- {
- if (!pSectionMgrInitialized)
- {
- TSectionMgr * aSectionMgr = new TSectionMgr; // instantiate a section mgr
- aSectionMgr->ISectionMgr(); // initialize it
- gDispatcher->AddBehavior(aSectionMgr); // give the application this behavior
-
- pSectionMgrInitialized = TRUE;
- }
- } // InitUSectionMgr
-
- //----------------------------------------------------------------------------------------
- // End of USectionMgr.cp
-
- #pragma segment Inline
-